import { POST } from '../axios.config.js'

const base = window.config.ip
const lib = `${base}/topnet-assess/sa-assess-template`
const taskApi = `${base}/topnet-assess/sa-assess-task/`

const URLS = {
  queryAssessTemplateList: `${lib}/queryAssessTemplateList`, // 考核配置数据列表分页查询
  getDefaultConfig: `${lib}/getDefaultConfig`, // 获取默认模版配置
  saveAssessTemplate: `${lib}/saveAssessTemplate`, // 保存考核模版
  delAssessTemplate: `${lib}/delAssessTemplate`, // 删除考核模版
  getAssessTemplateDetail: `${lib}/getAssessTemplateDetail`, // 获取考核模版详情
  getAssessArea: `${lib}/getAssessArea`, // 获取考核范围
  listAssessModel: `${lib}/listAssessModel`, // 获取考核评价模型
  queryTemplateList: `${taskApi}/queryTemplateList`, // 获取考核模板
  copyTemplate: `${lib}/copyTemplate`, // 复制模板内容
}

// 考核配置数据列表分页查询
export const queryAssessTemplateList = ({ keywords, status, tenantId, templateType }, currentPage = 1, pageSize = 10) =>
  POST(URLS.queryAssessTemplateList, {
    param: {
      keywords,
      status,
      tenantId: localStorage.pskh_tenantId,
      templateType,
    },
    currentPage,
    pageSize,
  })

// 获取默认模版配置
export const getDefaultConfig = tenantId =>
  POST(URLS.getDefaultConfig, {
    tenantId: localStorage.pskh_tenantId,
  })

// 保存考核模版
export const saveAssessTemplate = ({
  assessType,
  configList,
  id,
  modelId,
  scoreType,
  scoreDTO,
  status,
  templateName,
  templateType,
}) =>
  POST(URLS.saveAssessTemplate, {
    assessType,
    configList,
    id,
    modelId,
    scoreType,
    scoreDTO,
    status,
    templateName,
    templateType,
    tenantId: localStorage.pskh_tenantId,
  })

// 删除考核模版
export const delAssessTemplate = id =>
  POST(URLS.delAssessTemplate, {
    id,
  })

// 获取考核模版详情
export const getAssessTemplateDetail = id =>
  POST(URLS.getAssessTemplateDetail, {
    id,
  })

// 获取考核范围
export const getAssessArea = (occurrenceTime, oneParam) =>
  POST(URLS.getAssessArea, {
    occurrenceTime,
    oneParam,
    tenantId: localStorage.pskh_tenantId,
  })

// 获取考核评价模型
export const listAssessModel = ({ modelState, modelStr, productId, tenantId }) =>
  POST(URLS.listAssessModel, {
    modelState,
    modelStr,
    productId,
    tenantId: localStorage.pskh_tenantId,
  })

// 获取考核模板
export const queryTemplateList = () => POST(URLS.queryTemplateList, {})

// 复制模板内容
export const copyTemplate = id =>
  POST(URLS.copyTemplate, {
    id,
  })
